package com.zhc.dejingapi.service.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhc.dejingapi.common.result.Result;
import com.zhc.dejingapi.common.utils.StringToLocalDateTimeUtils;
import com.zhc.dejingapi.entity.QingZbProductionOrderPoolEntity;
import com.zhc.dejingapi.entity.vo.QingProductionOrderPoolEntityVo;
import com.zhc.dejingapi.mapper.QingZbProductionOrderPoolMapper;
import com.zhc.dejingapi.service.QingZbProductionOrderPoolService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhc
 * @since 2024-09-12
 */
@Service
public class QingZbProductionOrderPoolServiceImpl extends ServiceImpl<QingZbProductionOrderPoolMapper, QingZbProductionOrderPoolEntity> implements QingZbProductionOrderPoolService {

    @Resource
    private QingZbProductionOrderPoolMapper qingZbProductionOrderPoolMapper;
    @Resource
    private StringToLocalDateTimeUtils stringToLocalDateTimeUtils;
    @Override
    public Result addProductionOrderPool(QingProductionOrderPoolEntityVo qingProductionOrderPoolEntity) throws IllegalAccessException {

        QingZbProductionOrderPoolEntity qingProductionOrderPool= new QingZbProductionOrderPoolEntity();
        qingProductionOrderPool.setInvCode(qingProductionOrderPoolEntity.getInvCode());
        qingProductionOrderPool.setInvName(qingProductionOrderPoolEntity.getInvName());
        qingProductionOrderPool.setInvType(qingProductionOrderPoolEntity.getInvType());
        qingProductionOrderPool.setOrderQuantity(qingProductionOrderPoolEntity.getOrderQuantity());
        qingProductionOrderPool.setPlanStartTime(DateUtil.parse(qingProductionOrderPoolEntity.getPlanStartTime()));
        qingProductionOrderPool.setPlanEndTime(DateUtil.parse(qingProductionOrderPoolEntity.getPlanStartTime()));
        qingProductionOrderPool.setProductionOrderCode(qingProductionOrderPoolEntity.getProductionOrderCode());
        qingProductionOrderPool.setQuantityTran(qingProductionOrderPoolEntity.getQuantityTran());
        qingProductionOrderPool.setUntranQuantity(qingProductionOrderPoolEntity.getUntranQuantity());
        qingProductionOrderPool.setMainId(qingProductionOrderPoolEntity.getMainId());

        int insert = qingZbProductionOrderPoolMapper.insert(qingProductionOrderPool);
        if(insert>0){
            return Result.ok(null);
        }else {
            return Result.fail(null);
        }

    }
}
